﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace InfonavaEye.util
{
    public  class FileHelper
    {
        private static string baseDir = null;
        public static string getBaseDir() {
            if (!String.IsNullOrEmpty(baseDir)) {
                return baseDir;
            }
            else
            {
                IntPtr strPath = Marshal.StringToHGlobalAnsi(System.Environment.CurrentDirectory);
                return Marshal.PtrToStringAnsi(strPath);
            }
        }

        /// <summary>
        /// 获取文件内容
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string readFile(string filePath) {
            return File.ReadAllText(filePath);
        }

        public static void openDir(String filePath)
        {
            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
            psi.Arguments = "/e,/select," + filePath;
            System.Diagnostics.Process.Start(psi);
        }

        public static void saveFile(string content, string path)
        {
            File.WriteAllText(path, content, Encoding.UTF8);
        }

        public static void removeFile(string path) {
            File.Delete(path);
        }
    }
}
